//
//  QDAdvertisementModel.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/7.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit
import HandyJSON

/// 地铁轮播提的模型
struct QDAdvertisementModel: HandyJSON {
    /// 广告分享用的标题
    var title = ""
    /// 跳转的url
    var url = ""
    /// 模块类型
    var moduleType = ""
    /// 展示的url
    var imgUrl = ""
    /// 类型
    var type = ""
    /// 是否是活动盒子
    var isBox: Bool {
        return type == "4"
    }
    /// 活动盒子的key
    var boxKey = ""
}


/// 地铁功能项的模型
struct QDFunctionModel: HandyJSON {
    
    /// 功能id
//    var id = ""
    /// 功能名称
    var title = ""
    /// 模块id
    var moduleId = ""
    /// 图片url
    var imgUrl = ""
    /// 是否是git
    var isGif = false
    /// 跳转的url,为了适配web
    var linkUrl = ""
    /// 跳转的url的网页title
//    var linkTitle = ""
    
    mutating func mapping(mapper: HelpingMapper) {
        mapper <<<
         self.title <-- "function"
        mapper <<<
         self.isGif <-- "gif"
//        mapper <<<
//         self.linkTitle <-- "title"
    }
}

extension String {
    
    enum ModuleIdType {
        /// 站点信息
        case stations
        /// 未知
        case unknown
    }
    
//    /// 站点类型
//    var moduleIdPlatformKey: String  {
//        get {
//            switch self {
//            case "13": return QDRouterPlatformStations
//            case "20": return QDRouterPlatformNews
//            case "3": return QDRouterPlatformLife
////            case "-1": return
//            default: return ""
//            }
//        }
//    }
    
}


/// 主页广告位
struct QDImageListModel: HandyJSON {
    
    /// 分享用的title
    var title = ""
    /// 跳转的url
    var url = ""
    /// 模块类型
    var moduleType = ""
    /// 图片的url
    var imgUrl = ""
    /// 类型
    var type = ""
    /// 是否是活动盒子
    var isBox: Bool {
        return type == "4"
    }
    /// 活动盒子的key
    var boxKey = ""
}


/// 公告模型
struct QDNoticesModel: HandyJSON {
 
    /// 公告标题
    var title = ""
    /// 跳转的url
    var webUrl = ""
    
    /// 紧急公告用的跳转的url
    var url = ""
    /// 紧急公告用来判定的字段
    var type = ""
    
    /// 是否存在紧急公告
    var hasNotices: Bool {
        get {
           return type == "0" ? false : true
        }
    }
}


/// 资讯模型
struct QDDocumentsModel: HandyJSON {
    
    /// id
    var id = ""
    /// 资讯标题
    var title = ""
    /// 点击跳转的url
    var webUrl = ""
    /// 图片的url
    var image = ""
    /// 时间戳
    var time = ""
    /// 作者
    var author = ""
    /// 是否点赞
    var favorited = false
    /// 点赞数
    var favoriteNum = 0
    /// 阅读数
    var readNum = 0
    /// 阅读数的字符串
    var readString: String {
        get {
            if readNum < 1000 { return "\(readNum)" }
            else if readNum < 10000 { return String(format: ".1fk", Double(readNum) / 1000.0) }
            return String(format: ".1f万",  Double(readNum) / 10000.0)
        }
    }
    /// 显示的时间字符串
    var timeString: String {
        get {
            let time = (TimeInterval(self.time) ?? 0.0) / 1000.0
            let calendar = Calendar.current
            let nowCmps = calendar.component(.year, from: Date())
            let sourceCmps = calendar.component(.year, from: Date(timeIntervalSince1970:time))
//            let formatter = nowCmps == sourceCmps ? "MM-dd HH:mm" : "yyyy-MM-dd HH:mm"
            let formatter = nowCmps == sourceCmps ? "MM-dd" : "yyyy-MM-dd"
            return DateFormatter.cachedDataFormatter(with: formatter).string(from: Date(timeIntervalSince1970: time))
        }
    }
}

